{% set adjacent = 3 %}
{% set pageTotal = cve['total'] %}
{% set pageCurrent = (r / pageLength)|int + 1 %}
{% set pageLast = (pageTotal / pageLength)|int %}
{% if(pageTotal % pageLength > 0) %}
  {% set pageLast = pageLast + 1 %}
{% endif %}
<div class="pagerdiv">
  <nav>
    <ul class="pagination">
{% if(pageLast >= 1) %}
  {% if(pageCurrent > 1) %}
    <li><a href="javascript:paginator_jump({{r - pageLength}})">&laquo;</a></li>
  {% else %}
    <li class="disabled"><a>&laquo;</a></li>
  {% endif %}
  {% if(pageLast < 7 + (adjacent * 2)) %}
    {% for n in range(1, pageLast + 1) %}
      {% if(n == pageCurrent) %}
        <li class="active"><a href="">{{n}}</a></li>
      {% else %}
        <li><a href="javascript:paginator_jump({{(n - 1) * pageLength}})">{{n}}</a></li>
      {% endif %}
    {% endfor %}
  {% elif(pageLast > 5 + (adjacent * 2)) %}
    {% if(pageCurrent < 1 + (adjacent * 2)) %}
      {% for n in range(1, 4 + (adjacent * 2)) %}
        {% if(n == pageCurrent) %}
          <li class="active"><a href="">{{n}}</a></li>
        {% else %}
  	  <li><a href="javascript:paginator_jump({{(n - 1) * pageLength}})">{{n}}</a></li>
        {% endif %}
      {% endfor %}
      <li class="disabled"><a>..</a></li>
      <li><a href="javascript:paginator_jump({{(pageLast - 2) * pageLength}})">{{pageLast - 1}}</a></li>
      <li><a href="javascript:paginator_jump({{(pageLast - 1) * pageLength}})">{{pageLast}}</a></li>
    {% elif(pageLast - (adjacent * 2) > pageCurrent and pageCurrent > (adjacent * 2)) %}
      <li><a href="javascript:paginator_jump({{0}})">1</a></li>
      <li><a href="javascript:paginator_jump({{pageLength}})">2</a></li>
      <li class="disabled"><a>..</a></li>
      {% for n in range(pageCurrent - adjacent, pageCurrent + adjacent + 1) %}
        {% if(n == pageCurrent) %}
          <li class="active"><a href="">{{n}}</a></li>
        {% else %}
	  <li><a href="javascript:paginator_jump({{(n - 1) * pageLength}})">{{n}}</a></li>
        {% endif %}
      {% endfor %}
      <li class="disabled"><a>..</a></li>
      <li><a href="javascript:paginator_jump({{(pageLast - 2) * pageLength}})">{{pageLast - 1}}</a></li>
      <li><a href="javascript:paginator_jump({{(pageLast - 1) * pageLength}})">{{pageLast}}</a></li>
    {% else %}
      <li><a href="javascript:paginator_jump({{0}})">1</a></li>
      <li><a href="javascript:paginator_jump({{pageLength}})">2</a></li>
      <li class="disabled"><a>..</a></li>
      {% for n in range(pageLast - (2 + (adjacent * 2)), pageLast + 1) %}
        {% if(n == pageCurrent) %}
          <li class="active"><a href="">{{n}}</a></li>
        {% else %}
	  <li><a href="javascript:paginator_jump({{(n - 1) * pageLength}})">{{n}}</a></li>
        {% endif %}
      {% endfor  %}
    {% endif %}
  {% endif %}
  {% if(pageCurrent < pageLast) %}
    <li><a href="javascript:paginator_jump({{r + pageLength}})">&raquo;</a></li>
  {% else %}
    <li class="disabled"><a>&raquo;</a></li>
  {% endif %}
{% endif %}
    </ul>
  </nav>
</div>
